<template>
  <div class="list-table">
    <div class="meetingReserve">
      <el-button size="small" plain @click="getPastWeek">{{ $t('上一周') }}</el-button>
      <h2>{{ $t('会议室预订情况') }}</h2>
      <el-button size="small" plain @click="getLastWeek">{{ $t('下一周') }}</el-button>
    </div>
    <el-table
      :data="listData"
      class="initTable"
    >
      <el-table-column
        v-for="(item,index) in listHeader"
        :key="index"
        align="center"
        :prop="item"
        :label="item"
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <a v-if="index === 0">{{ scope.row.name }}</a>
          <a v-else class="link_a" @click="orderRoom()">可预订</a>
        </template>
      </el-table-column>

    </el-table>
    <el-dialog title="预订会议室" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm">
      <meetingRoomReserveForm />
    </el-dialog>
  </div>
</template>
<script>
import meetingRoomReserveForm from './meetingRoomReserveForm.vue'
export default {
  name: 'MeetingRoomReserve',
  components: {
    meetingRoomReserveForm
  },
  data() {
    return {
      listHeader: ['会议室'],
      listData: [
        { name: '会议室1' },
        { name: '会议室1' }
      ],
      formOpen: false
    }
  },
  mounted() {
    //  this.getPastWeek()
     this.getLastWeek()
  },
  methods: {
    orderRoom() {
      this.formOpen = true
    },
    // 获取下一周
    getLastWeek() {
      this.listHeader = ['会议室']
      for (let i = 0; i <= 6; i++) {
        this.listHeader.push(this.getWeek(+i))
      }
      console.log(this.listHeader)
    },
    // 获取上一周
    getPastWeek() {
      this.listHeader = ['会议室']
      for (let i = 6; i >= 0; i--) {
        this.listHeader.push(this.getWeek(-i))
      }
    },

    // 获取一周
    getWeek(day) {
        var today = new Date()
        var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day
        today.setTime(targetday_milliseconds)
        var tYear = today.getFullYear()
        var tMonth = today.getMonth()
        var tDate = today.getDate()
        tMonth = this.doHandleMonth(tMonth + 1)
        tDate = this.doHandleMonth(tDate)
        return tYear + '-' + tMonth + '-' + tDate
    },
    doHandleMonth(month) {
        var m = month
        if (month.toString().length === 1) {
          m = '0' + month
        }
        return m
    }

  }
}
</script>
